import java.io.IOException;


public class GameParser extends Parser
{
    private Game game;
    
//    public static HashMap<String, Integer> teamIDs = new HashMap<String, Integer>();
//    
//    static {
//        teamIDs.put("BAL", 1);
//        teamIDs.put("BOS", 2);
//        teamIDs.put("NYA", 3);
//        teamIDs.put("TBA", 4);
//        teamIDs.put("TOR", 5);
//        teamIDs.put("CHA", 6);
//        teamIDs.put("CLE", 7);
//        teamIDs.put("DET", 8);
//        teamIDs.put("KAN", 9);
//        teamIDs.put("MIN", 10);
//        
//        teamIDs.put("ANA", 1);
//        teamIDs.put("BOS", 2);
//        teamIDs.put("NYA", 3);
//        teamIDs.put("TBA", 4);
//        teamIDs.put("TOR", 5);
//        teamIDs.put("CHA", 6);
//        teamIDs.put("CLE", 7);
//        teamIDs.put("DET", 8);
//        teamIDs.put("KAN", 9);
//        teamIDs.put("MIN", 10);
//    }
    
    public GameParser(int type, String arg) throws IOException
    {
        super(arg);
        
        game = new Game();
        game.type = type;
    }

    public void parse() throws IOException
    {
        String line;
        while ((line = reader.readLine()) != null)
        {
            String[] fields = line.split(",");
            
            game.awayscore = Integer.parseInt(fields[9]);
            game.homescore = Integer.parseInt(fields[10]);
            
            game.played_on = fields[0].substring(1, 9);
            
            game.awayteam = fields[3].substring(1, 4);
            game.hometeam = fields[6].substring(1, 4);
            
            game.gid = game.hometeam + game.played_on + fields[1].charAt(1);
            
            writer.write(game.toString());
        }
        reader.close();
        writer.close();
    }

    class Game
    {
        String gid;
        String played_on;
        int type;
        String hometeam;
        String awayteam;
        int homescore, awayscore;
        
        public String toString()
        {
            return "INSERT INTO Games (gid, played_on, type, hometeam, awayteam, homescore, awayscore) VALUES ('"
                    + gid + "', TO_DATE('" + played_on + "', 'yyyymmdd'), " + type + ", '" + hometeam + "', '" + awayteam + "', "
                    + homescore + ", " + awayscore + ");\n";
        }
    }
}
